<template>
  <Dialog :title="t('studentHonorArchive.view.title')" v-model="dialogVisible" width="1400">
    <el-descriptions v-loading="formLoading" :column="2" border label-width="150">
      <el-descriptions-item :label="t('studentHonorArchive.fields.reviewStatus')" width="280">
        <el-tag v-if="formData.reviewStatus" type="primary">{{ formData.reviewStatus }}</el-tag>
      </el-descriptions-item>
      <el-descriptions-item :label="t('studentHonorArchive.fields.reviewerName')" width="280">
        <el-tag v-if="formData.reviewerName" type="primary">{{ formData.reviewerName }}</el-tag>
      </el-descriptions-item>
      <el-descriptions-item :label="t('studentHonorArchive.fields.reviewTime')" width="280">
        {{ formatDate(formData.reviewTime) }}
      </el-descriptions-item>
      <el-descriptions-item :label="t('studentHonorArchive.fields.reviewComments')" width="280">
        {{ formData.reviewComments }}
      </el-descriptions-item>
      <el-descriptions-item :label="t('studentHonorArchive.fields.studentCode')" width="280">
        <EditInput
          v-model="formData.studentCode"
          :placeholder="
            t('common.inputTextPlaceholder') + t('studentHonorArchive.fields.studentCode')
          "
          :disabled="true"
        />
      </el-descriptions-item>
      <el-descriptions-item :label="t('studentHonorArchive.fields.studentName')" width="280">
        <EditInput
          v-model="formData.studentName"
          :placeholder="
            t('common.inputTextPlaceholder') + t('studentHonorArchive.fields.studentName')
          "
          :disabled="true"
        />
      </el-descriptions-item>
      <el-descriptions-item :label="t('studentHonorArchive.fields.honorName')" width="280">
        <EditInput
          v-model="formData.honorName"
          :placeholder="
            t('common.inputTextPlaceholder') + t('studentHonorArchive.fields.honorName')
          "
        />
      </el-descriptions-item>
      <el-descriptions-item :label="t('studentHonorArchive.fields.honorTime')" width="280">
        <EditDate
          v-model="formData.honorTime"
          :placeholder="
            t('common.inputTextPlaceholder') + t('studentHonorArchive.fields.honorTime')
          "
        />
      </el-descriptions-item>
      <el-descriptions-item :label="t('studentHonorArchive.fields.honorType')" width="280">
        <EditDict
          :dict-type="DICT_TYPE.HONOR_TYPE"
          v-model="formData.honorType"
          :placeholder="
            t('common.selectTextPlaceholder') + t('studentHonorArchive.fields.honorType')
          "
        />
      </el-descriptions-item>
      <el-descriptions-item :label="t('studentHonorArchive.fields.teamHonor')" width="280">
        <EditDict
          :dict-type="DICT_TYPE.HONOR_TEAM_HONOR"
          v-model="formData.teamHonor"
          :placeholder="
            t('common.selectTextPlaceholder') + t('studentHonorArchive.fields.teamHonor')
          "
        />
      </el-descriptions-item>
      <el-descriptions-item :label="t('studentHonorArchive.fields.ranking')" width="280">
        <EditDict
          :dict-type="DICT_TYPE.HONOR_RANKING"
          v-model="formData.ranking"
          :placeholder="t('common.selectTextPlaceholder') + t('studentHonorArchive.fields.ranking')"
        />
      </el-descriptions-item>
      <el-descriptions-item :label="t('studentHonorArchive.fields.mentorName')" width="280">
        <UserSelect
          v-model="formData.mentorId"
          :placeholder="
            t('common.selectTextPlaceholder') + t('studentHonorArchive.fields.mentorName')
          "
        />
      </el-descriptions-item>
      <el-descriptions-item
        :label="t('studentHonorArchive.fields.attachment')"
        width="280"
        :span="2"
      >
        <IMRUpload v-model="formData.attachment" disabled />
      </el-descriptions-item>
      <el-descriptions-item :label="t('studentHonorArchive.fields.remark')" width="280" :span="2">
        <EditInput
          v-model="formData.remark"
          type="textarea"
          :rows="3"
          :maxlength="200"
          show-word-limit
          :placeholder="t('common.inputTextPlaceholder') + t('studentHonorArchive.fields.remark')"
        />
      </el-descriptions-item>
    </el-descriptions>

    <template #footer>
      <el-button @click="dialogVisible = false">{{ t('common.cancel') }}</el-button>
    </template>
  </Dialog>
</template>
<script setup lang="ts">
import { StudentHonorArchiveApi, StudentHonorArchiveVO } from '@/api/core/studenthonorarchive'
import { DICT_TYPE } from '@/utils/dict'
import { formatDate } from '@/utils/formatTime'
import EditDate from '@/components/EditViewInput/EditDate.vue'
import IMRUpload from '@/components/IMRUpload/index.vue'
import UserSelect from '@/components/TeacherSelect/index.vue'
import EditInput from '@/components/EditViewInput/EditInput.vue'
import EditDict from '@/components/EditViewInput/EditDict.vue'

/** 荣誉奖项审核归档 表单 */
defineOptions({ name: 'StudentHonorArchiveForm' })

const { t } = useI18n() // 国际化
const message = useMessage() // 消息弹窗

const dialogVisible = ref(false) // 弹窗的是否展示
const formLoading = ref(false) // 表单的加载中：1）修改时的数据加载；2）提交的按钮禁用
const formData = ref<Partial<StudentHonorArchiveVO>>({})

// 归档没有编辑的可能
provide('editMode', false)

/** 打开弹窗 */
const open = async (id: number) => {
  dialogVisible.value = true
  formLoading.value = true
  formData.value = {}
  try {
    formData.value = await StudentHonorArchiveApi.getStudentHonorArchive(id)
    if (formData.value && !formData.value?.attachment) {
      formData.value.attachment = '[]'
    }
  } finally {
    formLoading.value = false
  }
}
defineExpose({ open }) // 提供 open 方法，用于打开弹窗
</script>
